import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orders: [{
      "report_number": "1",
      "report_name": "张三",
      "report_result": '缺少休息',
      "create_time": 1665731518
    }, {
      "report_number": "2",
      "report_name": "张三",
      "report_result": '缺少休息',
      "create_time": 1664731518
    }, {
      "report_number": "3",
      "report_name": "张三",
      "report_result": '缺少休息',
      "create_time": 1564731518
    }],
    //Tabs数据
    Tabs: [{
      id: 0,
      name: '推荐体验师',
      isActive: true
    }, {
      id: 1,
      name: '体检报告栏',
      isActive: false
    }, {
      id: 2,
      name: '云养艾草',
      isActive: false
    }, {
      id: 3,
      name: '艾灸历史',
      isActive: false
    }]
  },
  onShow(options) {
    //判断是否登陆
    const token = wx.getStorageSync('token')
    if (!token) {
      wx.navigateTo({
        url: '/pages/auth/auth',
      });
      return;
    }

    let pages = getCurrentPages();
    let { type } = pages[pages.length - 1].options;
    this.getOrderList(type)
  },
  //获取订单方法
  async getOrderList(type) {
    // const res = await request({ url: '/my/orders/all' }, { data: type })
    // this.setData({
    //     orders: res.orders.map(v => ({...v, create_time_cn: (new Date(v.create_time * 1000).toLocaleString()) }))
    // })
    //const res = await request({ url: '/my/orders/all' }, { data: type })
    let orders = this.data.orders;
    let newOrders = orders.map(v => ({ ...v, create_time_cn: (new Date(v.create_time * 1000).toLocaleString()) }))
    this.setData({
      orders: newOrders
    })
  },
  //切换Tab栏
  tabsItemChange(e) {
    const id = e.detail.id;
    const Tabs = this.data.Tabs;
    Tabs.forEach((v, i) => i === id ? v.isActive = true : v.isActive = false)

    if (id === 1) {
      wx.navigateTo({
        url: '/pages/checkup/checkup'
      });
      v.isActive = true
    }else if(id === 2){
        wx.navigateTo({
            url: '/pages/plant/plant'
        });
        v.isActive = true
    }
    this.setData({
      Tabs
    })

  }
})